<?php
$page_type = "A";
require_once 'header.php';

// Obtain information for the record to be updated
$client_id = $_POST["client_id"];
$sid = $_POST["sid"];
$password = $_POST["password"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$dob = $_POST["dob"];
$client_type = $_POST["client_type"];
$student_type = $_POST["student_type"];
$probation = $_POST["probation"];
$street = $_POST["street"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];

// Client type
if ($client_type == "A") {
  $aflag = "1";
  $sflag = "0";
}
else if ($client_type == "S") {
  $aflag = "0";
  $sflag = "1";
}
else if ($client_type == "B") {
  $aflag = "1";
  $sflag = "1";
}
else {
  $aflag = "0";
  $sflag = "0";
}

// Student type
if ($student_type == "U")
  $stflag = "0";
else if ($student_type == "G")
  $stflag = "1";
else
  $stflag = " ";

// Probation status
if ($probation == "y")
  $pflag = "1";
else if ($probation == "n")
  $pflag = "0";
else 
  $pflag = " ";

$sql = "update CLIENT set Client_ID='$client_id', Sid='$sid', Password='$password', Fname='$fname', Lname='$lname', 
        AFlag='$aflag', SFlag='$sflag', DOB='$dob', Street='$street', City='$city', State='$state', Zip='$zip', 
		STFlag='$stflag', PFlag='$pflag' where Client_ID='$client_id'";

$result_array = execute_sql_in_oracle($sql);
$result = $result_array["flag"];
$cursor = $result_array["cursor"];

if (!$result){
  // Store fields for update form
  $_SESSION['client_id'] = $client_id;
  $_SESSION['sid'] = $sid;
  $_SESSION['password'] = $password;
  $_SESSION['fname'] = $fname;
  $_SESSION['lname'] = $lname;
  $_SESSION['dob'] = $dob;
  $_SESSION['client_type'] = $client_type;
  $_SESSION['student_type'] = $student_type;
  $_SESSION['input_pflag'] = $probation;
  $_SESSION['street'] = $street;
  $_SESSION['city'] = $city;
  $_SESSION['state'] = $state;
  $_SESSION['zip'] = $zip;
  
  $update_error = 'Client ID('."<b><font color=\"black\">".$client_id."</font></b>".') update failed!';
  header("Location:client_update.php?update_error=$update_error");
}
else {
  // Record updated, redirect to client.php
  resetForm();
  $_SESSION['sid'] = "";
  $update_success = 'Client ID('."<b><font color=\"black\">".$client_id."</font></b>".') updated successfully!';
  header("Location:client.php?update_success=$update_success");
}
?>